package kr.ac.jejuuniv.controller;

import javax.validation.Valid;

import kr.ac.jejuuniv.model.User;
import kr.ac.jejuuniv.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/save")
public class UserSave {
	
	@Autowired
	private UserService userService;
//	@Autowired
//	private Validator validator;
//	private UserValidator validator;
//	@InitBinder
//	public void initBinder(WebDataBinder dataBinder) {
//		dataBinder.set.setValidator(validator);
//	}
	
	@RequestMapping(method=RequestMethod.POST)
	public String action(@ModelAttribute @Valid User user, BindingResult result) {
		if(result.hasErrors()) {
			return "modify";
		}
		userService.save(user);
		return "redirect:/list";
	}
}
